<template>
  <div class="swiper-div">
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl"/>
      </swiper-slide>

      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  data: function () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true
      }
    }
  },
  props: {
    list: Array
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  .swiper-div {
    overflow: hidden;
    width: 100%;
    height: 0;
    /* height / width = 26.67% */
    padding-bottom: 30%;
    background: #eee;
  }
  .swiper-img {
    width: 100%;
  }
  /* 样式穿透 不受scooed限制 */
  .swiper-div >>> .swiper-pagination-bullet-active {
    background: white;
  }
</style>
